package com.topone.permission.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.topone.permission.entity.SysUser;
import com.topone.permission.model.UserSeesion;
import com.topone.permission.result.Result;
import com.topone.permission.service.SysUserService;
import com.topone.permission.utils.ControllerUtils;

@RestController
@RequestMapping("/sysuser")
public class UserController {
	
	@Autowired
	SysUserService sysUserService;
	
	@RequestMapping("/create")
	public Result<?> create(@RequestBody SysUser user){
		sysUserService.save(user);
		return Result.success();
	}
	
	@RequestMapping("get/company/sysUser")
	public Result<?> create(){
		UserSeesion user = ControllerUtils.getUser();
		List<SysUser> list = sysUserService.findByCompanyCode(user.getCompanyCode());
		return Result.success(list);
	}
	
	@RequestMapping("edit/sysUser")
	public Result<?> editUserWithRole(Long userId,List<Long> roleIdList){
		sysUserService.editUserWithRole(userId, roleIdList);
		return Result.success();
	}
	

}
